home *** CD-ROM | disk | FTP | other *** search
- { gettext.pas -- Get text (if present) from clipboard }
-
- program GetText;
-
- uses WinTypes, WinProcs, WinCrt, Strings;
-
- const
-
- winCrtClassName = 'TPWinCrt';
-
- var
-
- HWindow: HWnd; { Handle to WinCrt window }
- P: PChar; { Pointer to pasted text }
-
- {- Return true if clipboard has some text }
- function TextInClipboard(HWindow: HWnd): Boolean;
- begin
- TextInClipboard := false;
- if OpenClipboard(HWindow) then
- begin
- if (IsClipboardFormatAvailable(cf_Text) or
- IsClipboardFormatAvailable(cf_OEMText)) then
- TextInClipboard := true;
- CloseClipboard
- end
- end;
-
- {- If true, P is allocated to a copy of clipboard's text }
- function GetClipText(HWindow: HWnd; var P: PChar): Boolean;
- var
- GHandle: THandle;
- GPtr: PChar;
- begin
- GetClipText := false;
- if TextInClipboard(HWindow) and OpenClipboard(HWindow) then
- begin
- GHandle := GetClipboardData(cf_Text);
- if GHandle <> 0 then
- begin
- GPtr := GlobalLock(GHandle);
- if GPtr <> nil then
- begin
- GetMem(P, StrLen(GPtr) + 1);
- if P <> nil then
- begin
- StrCopy(P, GPtr);
- GetClipText := true
- end;
- GlobalUnlock(GHandle)
- end
- end;
- CloseClipboard
- end
- end;
-
- begin
- InitWinCrt; { Registers window class for FindWindow }
- HWindow := FindWindow(winCrtClassName, nil);
- if HWindow = 0 then
- Writeln('*** Unable to find WinCrt''s window handle')
- else begin
- if not TextInClipboard(HWindow) then
- Writeln('No text available in clipboard')
- else begin
- if GetClipText(HWindow, P) then
- begin
- Writeln('>', P);
- StrDispose(P)
- end else
- Writeln('*** Unable to get text from clipboard')
- end
- end
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/25/1991
- ---------------------------------------------------------------}
-